package handlers

import (
	"context"
	"douyin_mini/cmd/api/rpc"
	"douyin_mini/kitex_gen/comment"
	"douyin_mini/pkg/constants"
	"douyin_mini/pkg/errno"
	"github.com/cloudwego/hertz/pkg/app"
	"github.com/hertz-contrib/jwt"
	"strconv"
)

func CommentList(ctx context.Context, c *app.RequestContext) {
	claims := jwt.ExtractClaims(ctx, c)
	userID := int64(claims[constants.IdentityKey].(float64))
	VideoIDStr := c.Query("video_id")
	VideoID, err := strconv.ParseInt(VideoIDStr, 10, 64)
	if err != nil {
		SendResponse(c, errno.ConvertErr(err), nil)
	}
	req := &comment.CommentListRequest{
		UserId:  userID,
		VideoId: VideoID,
	}
	listComment, err := rpc.ListComment(ctx, req)
	if err != nil {
		SendResponse(c, errno.ConvertErr(err), nil)
	}
	SendResponse(c, errno.Success, listComment)
}
